package server;

/**
 * http协议工具类 主要提供响应头信息 这里我们只提供200和404的情况
 *
 * @author Fxz
 * @version 1.0
 * @date 2021-08-23 16:03
 */
public class HttpProtocolUtil {

    /**
     * 为响应码200提供请求头信息
     *
     * @return
     */
    public static String getHttpHeader200(Integer contentLength ) {
        return "HTTP/1.1 200 OK\n" +
                "Content-Type: text/html;charset=utf-8\n" +
                "Content-Length: "+contentLength+"\n"+
                "\r\n";
    }

    /**
     * 为响应码404提供请求头信息(此处也包含了数据内容)
     *
     * @return
     */
    public static String getHttpHeader404() {
        String str404 = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 NOT Found\n" +
                "Content-Type: text/html;charset=utf-8\n" +
                "Content-Length: "+str404.getBytes().length+"\n"+
                "\r\n"+str404;
    }

}
